package com.platform.api;

import com.platform.annotation.IgnoreAuth;
import com.platform.annotation.LoginUser;
import com.platform.entity.*;
import com.platform.service.ApiUserService;
import com.platform.service.ApiZbIntimacyService;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 亲密值排行榜
 *
 * @author zhurusen
 * @email 524227263@qq.com
 * @date 2018-05-15 15:50:14
 */
@RestController
@RequestMapping("api/intimacy")
public class ApiIntimacyController {
    @Autowired
    private ApiUserService apiUserService;
    @Autowired
    private ApiZbIntimacyService apiZbIntimacyService;


    /**
     * 查看列表
     */
    @IgnoreAuth
    @RequestMapping("/ranking")
    public R list(@LoginUser UserVo loginUser, Long userId, @RequestParam(value = "page", defaultValue = "1") Integer page) {
        //查询列表数据
        Map<String, Object> params = new HashMap<>();
        params.put("page", page);
        params.put("limit", 100);
        params.put("zbUserId", userId);

        params.put("sidx", "id");
        params.put("order", "desc");
        Query query = new Query(params);

        List<Map<String, Object>> list = apiZbIntimacyService.queryBanking(query);
        for (Map<String, Object> map : list) {
            Long cmUserId = Long.valueOf(map.get("userId").toString());
            UserInfo userInfo = apiUserService.toUserInfo(cmUserId, loginUser);
            map.put("cmUser", userInfo);
        }

        return R.ok(0, "获取成功", list);
    }

}
